import { BaseInjectHandler } from "../BaseInjectHandler";
import { EMessageC2C } from "../../../common/EMessageC2C";
import { HandleQuerySceneImg } from "./HandleQuerySceneImg";
import { TransPack } from "../../../server/framework/common/TransPack";
import { CommonOperateBack } from "../common/CommonOperateBack";

export class HandleResetCameraPos extends BaseInjectHandler {

    msgId: number = EMessageC2C.ResetCameraPos;

    private _cameraHandle: HandleQuerySceneImg;

    _OnInit() {
        this._cameraHandle = this.owner.GetHandleById(EMessageC2C.QuerySceneImg) as HandleQuerySceneImg;
    }

    _OnHandleMsg(msg: TransPack) {

        let backData = new CommonOperateBack();
        if (!this._cameraHandle.isAbleToRender) {
            backData.code = -1;
            this.owner.SendTransOtherData(EMessageC2C.CommonOperate_Back, backData);
            return;
        }

        let searchCamera = this._cameraHandle.SearchCamera();
        if (searchCamera == null) {
            backData.code = -1;
            this.owner.SendTransOtherData(EMessageC2C.CommonOperate_Back, backData);
            return;
        }
        this._cameraHandle.workCamera.transform.position = searchCamera.transform.position.clone();
        this._cameraHandle.workCamera.transform.rotation = searchCamera.transform.rotation.clone();

        backData.code = 1;
        this.owner.SendTransOtherData(EMessageC2C.CommonOperate_Back, backData);
    }

}